<?php

namespace App\Admin\Controllers;

use App\Models\User;
use Encore\Admin\Grid;
use Encore\Admin\Controllers\AdminController;

class GradesController extends AdminController
{
    protected $title = '会员层级检索';
    
    protected function grid()
    {
        $grid = new Grid(new User());
	    $grid->model()->orderByDesc('id');
	
	    if ($parentId = request('user_id')) {
		    $grid->model()->where('parent_id', $parentId)->orderByDesc('id');
	    }
	    
	    $grid->column('name', '会员')->display(function () {
		    return $this->nameText(true);
	    });
        $grid->column('grade', '身份')->display(function () {
        	return $this->gradeText();
        });
        $grid->column('invite_code', '邀请码')->copyable();
	    $grid->column('created_at', '创建时间')->display(function () {
		    return (string)$this->created_at;
	    });
        $grid->column('is_locked', '锁定')->display(function () {
        	return $this->lockedText(true);
        });
        
        $grid->disableCreateButton();
        $grid->disableColumnSelector();
        $grid->disableRowSelector();
        $grid->disableExport();
        $grid->disableActions();
        
        return $grid;
    }
}
